<template>
  <div>
    <el-table :data="list" style="width: 100%" max-height="300">
      <el-table-column type="index" />
      <el-table-column prop="keyword" label="关键词" />
      <el-table-column sortable prop="num" label="人数" />
      <el-table-column
        sortable
        prop="pie"
        label="周增长率"
        :formatter="pieFormatter"
      />
    </el-table>
    <el-row type="flex" justify="end">
      <el-pagination
        background
        :current-page="queryData.page"
        :page-sizes="[10, 20, 50]"
        :page-size="queryData.size"
        layout="prev, pager, next"
        :total="50"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-row>
  </div>
</template>

<script>
import { getEchar } from '@/api/echs'
export default {
  data() {
    return {
      queryData: {
        page: 1,
        size: 10
      },
      list: []
    }
  },
  created() {
    this.initData()
  },
  methods: {
    handleSizeChange(val) {
      this.queryData.size = val
      this.initData()
    },
    handleCurrentChange(val) {
      this.queryData.page = val
      this.initData()
    },
    async initData() {
      const { six } = await getEchar(this.queryData)
      this.list = six
    },
    pieFormatter(row, column, cellValue, index) {
      return cellValue + '%'
    }
  }
}
</script>

<style scoped>
</style>
